package com.bawei.hgshop.service.impl;

import java.util.List;

import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;

import com.bawei.hgshop.entity.Category;
import com.bawei.hgshop.mapper.CategoryMapper;
import com.bawei.hgshop.service.CategoryService;

@Service(interfaceClass = CategoryService.class)
public class CategoryServiceImpl implements CategoryService {
	
	//分类的Mapper
	@Autowired
	CategoryMapper catMapper;

	@Override
	public List<Category> tree() {
		// TODO Auto-generated method stub
		return catMapper.listByPid(0);
	}

	@Override
	public int delById(int id) {
		// TODO Auto-generated method stub
		// 如果 有孩子的话 不让删除
		List<Category> byPid = catMapper.listByPid(id);
		//
		if(byPid !=null && byPid.size()>0) {
			return -1;
		}
		// 可以删除
		
		return catMapper.delete(id);
	}

	@Override
	public int update(Category category) {
		// TODO Auto-generated method stub
		return catMapper.update(category);
	}

	@Override
	public int add(Category category) {
		// TODO Auto-generated method stub
		return catMapper.add(category);
	}

}
